﻿package mortal.game.view.copy.crossMainCity.panels
{
    import Message.DB.Tables.*;
    import Message.Game.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.text.*;
    import frEngine.pools.*;
    import frEngine.primitives.object2d.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.model.player.*;
    import mortal.game.scene3D.model.pools.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.game.scene3D.player.info.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.crossMainCity.*;
    import mortal.mvc.core.*;

    public class MainCityFinalPanel extends GSprite
    {
        private var _txtNextOpenTime:GTextFiled;
        private var _txtKingsName:GTextFiled;
        private var _bmpKingNo:GImageBitmap;
        private var _txtCannotSignUp:GTextFiled;
        private var _txtGuildInControl:GTextFiled;
        private var _txtTotalGold:GTextFiled;
        private var _txtMyGold:GTextFiled;
        private var _btnGetMyGold:GLoadingButton;
        private var _btnEnter:GLoadingButton;
        private var _window:Window;
        private var _bg:GImageBitmap;
        private var _effectPlayer:EffectPlayer;
        private var _rolePlayer:UserModelPlayer;
        private var _img2d:Img2D;
        private var _rect3d:Rect3DObject;
        private var _sp3D:GSprite;
        private var _kingInfo:SMainCityPositon;
        private var _bgLoaded:Boolean = false;
        private var _kingInfoGot:Boolean = false;

        public function MainCityFinalPanel(param1:Window)
        {
            this._window = param1;
            return;
        }// end function

        private function add3d() : void
        {
            this._rect3d = Rect3DManager.instance.registerWindow(true, new Rectangle(9, 67, 881, 543), this._window);
            Rect3DManager.instance.windowShowHander(null, this._window);
            return;
        }// end function

        private function add2d() : void
        {
            var _loc_1:BitmapData = null;
            if (this.isDisposed)
            {
                return;
            }
            this._bgLoaded = true;
            this.add3d();
            if (this._rect3d)
            {
                _loc_1 = this._bg.bitmapData;
                this._img2d = new Img2D(null, _loc_1, new Rectangle(0, 0, 881, 543), false);
                this._rect3d.addImg(this._img2d);
            }
            this.showKing();
            return;
        }// end function

        private function showKing() : void
        {
            var _loc_1:SMiniPlayer = null;
            var _loc_2:EntityInfo = null;
            var _loc_3:int = 0;
            var _loc_4:TTitle = null;
            if (!this._bgLoaded || !this._kingInfoGot)
            {
                return;
            }
            if (this._kingInfo)
            {
                if (this._bmpKingNo.parent != null)
                {
                    DisplayUtil.removeMe(this._bmpKingNo);
                }
                this._txtKingsName.textColor = 16435006;
                _loc_1 = this._kingInfo.officer;
                this._txtKingsName.text = NameUtil.getProxyName(_loc_1.entityId) + _loc_1.name;
                this._txtGuildInControl.textColor = 16444673;
                this._txtGuildInControl.text = Cache.instance.mainCity.sMainCityPositons.guildName;
                if (this._rect3d)
                {
                    if (this._rolePlayer == null)
                    {
                        this._rolePlayer = FrObjectPool.getObject(RoleModelPlayer, this);
                    }
                    _loc_2 = Cache.instance.role.roleEntityInfo;
                    _loc_3 = MainCityCache.getPostionClothIdByType(this._kingInfo.positon);
                    this._rolePlayer.updateIsShowEffect(true, true, true);
                    this._rolePlayer.updateInfo(_loc_1.career, _loc_1.sex, _loc_3, 0, 0, 0, _loc_1.VIP, true);
                    this._rolePlayer.scaleAll = 2;
                    this._rolePlayer.setRenderList(this._rect3d.renderList);
                    this._rolePlayer.rotationY = 0;
                    this._rect3d.addObject3d(this._rolePlayer, 435, 362);
                    _loc_4 = TitleConfig.instance.getInfoById(200200 + this._kingInfo.positon - 1);
                    if (this._effectPlayer)
                    {
                        this._rect3d.disposeObj3d(this._effectPlayer);
                    }
                    this._effectPlayer = EffectPlayerPool.instance.getEffectPlayer(_loc_4.icon, null, this._rect3d.renderList, false);
                    this._effectPlayer.play();
                    var _loc_5:int = 1;
                    this._effectPlayer.scaleZ = 1;
                    var _loc_5:* = _loc_5;
                    this._effectPlayer.scaleY = _loc_5;
                    this._effectPlayer.scaleX = _loc_5;
                    this._rect3d.addObject3d(this._effectPlayer, 430, 31);
                }
            }
            else
            {
                this._window.contentTopOf3DSprite.addChild(this._bmpKingNo);
                this._bmpKingNo.imgUrl = ImagesConst.MainCityKingNo;
                this._txtKingsName.textColor = 10066329;
                this._txtKingsName.text = Language.getString(20952);
                this._txtGuildInControl.text = Language.getString(20953);
                if (this._rolePlayer)
                {
                    this._rect3d.disposeObj3d(this._rolePlayer);
                    this._rolePlayer = null;
                }
                if (this._effectPlayer)
                {
                    this._rect3d.disposeObj3d(this._effectPlayer);
                    this._effectPlayer = null;
                }
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._sp3D = UICompomentPool.getUICompoment(GSprite) as GSprite;
            this._sp3D.x = 9;
            this._sp3D.y = 67;
            this._window.contentTopOf3DSprite.addChild(this._sp3D);
            this._bg = UIFactory.gImageBitmap(ImagesConst.MainCityWinBg, 0, 0, null, this.add2d);
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.MainCityFinalLeftBg, 13, 91, this._sp3D));
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.MainCityFinalRightBg, 592, 76, this._sp3D));
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.MainCityKingNameBg, 300, 43, this._sp3D));
            var _loc_1:* = UICompomentPool.getUICompoment(GSprite) as GSprite;
            _loc_1.x = 13;
            _loc_1.y = 91;
            this._sp3D.addChild(_loc_1);
            pushUIToDisposeVec(_loc_1);
            var _loc_2:* = GlobalStyle.textFormatPutong;
            _loc_2.color = 10663892;
            _loc_2.size = 12;
            var _loc_3:* = UIFactory.gTextField("", 16, 167, 257, 70, _loc_1, _loc_2);
            pushUIToDisposeVec(_loc_3);
            _loc_3.multiline = true;
            _loc_3.wordWrap = true;
            _loc_3.htmlText = Language.getString(20271);
            _loc_3 = UIFactory.gTextField("", 16, 271, 257, 70, _loc_1, _loc_2.clone());
            pushUIToDisposeVec(_loc_3);
            _loc_3.multiline = true;
            _loc_3.wordWrap = true;
            _loc_3.htmlText = Language.getString(20272);
            _loc_3 = UIFactory.gTextField("", 16, 376, 257, 70, _loc_1, _loc_2.clone());
            pushUIToDisposeVec(_loc_3);
            _loc_3.multiline = true;
            _loc_3.wordWrap = true;
            _loc_3.htmlText = Language.getString(20273);
            _loc_2 = _loc_2.clone();
            _loc_2.size = 15;
            this._txtNextOpenTime = UIFactory.gTextField("", 21, 67, 240, 24, _loc_1, _loc_2);
            this._txtNextOpenTime.textColor = 65280;
            this._txtNextOpenTime.text = Cache.instance.mainCity.getNextOpenDayStr() + "  19:50-20:20";
            _loc_2 = _loc_2.clone();
            _loc_2.size = 18;
            _loc_2.color = 10663892;
            _loc_2.align = TextFormatAlign.CENTER;
            this._txtKingsName = UIFactory.gTextField(Language.getString(20952), 313, 52, 240, 26, this._sp3D, _loc_2);
            this._bmpKingNo = UIFactory.gImageBitmap(null, 224, 100, this._sp3D);
            _loc_2 = GlobalStyle.textFormatLv;
            _loc_2.size = 14;
            _loc_2.color = 16711680;
            this._txtCannotSignUp = UIFactory.gTextField(Language.getString(20954), 370, 500, 240, 24, this._sp3D, _loc_2);
            if (Cache.instance.mainCity.canIEnterCurBattle && Cache.instance.mainCity.isFinalBattleDuration)
            {
                this._txtCannotSignUp.textColor = 65280;
                this._txtCannotSignUp.text = Language.getString(20955);
            }
            else if (!Cache.instance.mainCity.isFinalBattleDuration)
            {
                this._txtCannotSignUp.text = Language.getString(20956);
            }
            _loc_2 = GlobalStyle.textFormatHuang;
            _loc_2.size = 16;
            _loc_2.color = 16444673;
            this._txtGuildInControl = UIFactory.gTextField("", 735, 118, 130, 26, this._sp3D, _loc_2);
            _loc_2 = GlobalStyle.textFormatHuang2;
            _loc_2 = GlobalStyle.textFormatBai;
            _loc_2.size = 14;
            this._txtTotalGold = UIFactory.gTextField("0", 719, 328, 100, 24, this._sp3D, _loc_2.clone());
            this._txtMyGold = UIFactory.gTextField("0", 719, this._txtTotalGold.y + 115, 100, 24, this._sp3D, _loc_2.clone());
            this._btnGetMyGold = UIFactory.gLoadingButton(ImagesConst.GetGiftBtn_upSkin, 678, this._txtMyGold.y + 32, 114, 33, this._sp3D);
            this._btnGetMyGold.configEventListener(MouseEvent.CLICK, this.getRevenueInfo);
            this._btnEnter = UIFactory.gLoadingButton(ImagesConst.MainCityFinalEnterBtn_upSkin, 352, 366, 172, 135, this._sp3D);
            this._btnEnter.configEventListener(MouseEvent.CLICK, this.enterHandler);
            NetDispatcher.addCmdListener(ServerCommand.MainCityPostionInfoGet, this.updateKing);
            GameProxy.guild.getMainCityRevenueInfo();
            GameProxy.guild.getMainCityPostionInfo();
            return;
        }// end function

        private function getRevenueInfo(param1) : void
        {
            GameProxy.guild.getEveryDayProfit();
            return;
        }// end function

        public function updateRevenueInfo(param1:SMainCityRevenueMsg) : void
        {
            if (param1 == null)
            {
                return;
            }
            this._txtTotalGold.text = param1.totalRevenue.toString();
            this._txtMyGold.text = param1.playerProfit.toString();
            if (param1.isGetTodayProfit || param1.playerProfit <= 0)
            {
                this._btnGetMyGold.mouseChildren = false;
                this._btnGetMyGold.mouseEnabled = false;
                this._btnGetMyGold.filters = [FilterConst.colorFilter];
            }
            else
            {
                this._btnGetMyGold.mouseChildren = true;
                this._btnGetMyGold.mouseEnabled = true;
                this._btnGetMyGold.filters = [];
            }
            return;
        }// end function

        public function updateKing(param1:Object) : void
        {
            this._kingInfoGot = true;
            this._kingInfo = Cache.instance.mainCity.getPostionByPosType(EMainCityPosition._EMainCityKing);
            this.showKing();
            return;
        }// end function

        private function enterHandler(param1) : void
        {
            GameProxy.copy.enterCrossMainCityFinalBattle();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._bgLoaded = false;
            this._kingInfo = null;
            NetDispatcher.removeCmdListener(ServerCommand.MainCityPostionInfoGet, this.updateKing);
            this._txtNextOpenTime.dispose(param1);
            this._txtNextOpenTime = null;
            this._txtKingsName.dispose(param1);
            this._txtKingsName = null;
            this._bmpKingNo.dispose(param1);
            this._bmpKingNo = null;
            this._txtCannotSignUp.dispose(param1);
            this._txtCannotSignUp = null;
            this._txtGuildInControl.dispose(param1);
            this._txtGuildInControl = null;
            this._txtTotalGold.dispose(param1);
            this._txtTotalGold = null;
            this._txtMyGold.dispose(param1);
            this._txtMyGold = null;
            this._btnGetMyGold.dispose(param1);
            this._btnGetMyGold = null;
            this._btnEnter.dispose(param1);
            this._btnEnter = null;
            this._bg.dispose(param1);
            this._bg = null;
            if (this._img2d)
            {
                this._img2d.dispose();
                this._img2d = null;
            }
            if (this._rolePlayer)
            {
                this._rect3d.disposeObj3d(this._rolePlayer);
                this._rolePlayer = null;
            }
            if (this._effectPlayer)
            {
                this._rect3d.disposeObj3d(this._effectPlayer);
                this._effectPlayer = null;
            }
            if (this._rect3d)
            {
                Rect3DManager.instance.disposeRect3d(this._rect3d);
                this._rect3d = null;
            }
            this._kingInfoGot = false;
            return;
        }// end function

    }
}
